﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Business.Abstract;
using DataAccess.AbstractRepository;
using log4net;
using DataAccess.NHibernateHelper;
using DataAccess.Repository;
using Domain.Entity;

namespace Business.Service
{
    public class JobBookingServiceImpl : IJobBookingService
    {
        ILog log = LogManager.GetLogger("CustomerServiceImpl");
        IJobBookingRepository jobBookingRepo;

        public JobBookingServiceImpl()
        {
            jobBookingRepo = new JobBookingRepository(FluentNHibernateHelper.GetContext());
        }

        public IList<JobBooking> GetAllJobBookings()
        {
            return jobBookingRepo.List().Where(x => x.IsDeleted == false).ToList();
        }

        public void Save(JobBooking jobBooking)
        {
            log.Debug("Save JobBooking");
            jobBookingRepo.Insert(jobBooking);
            jobBookingRepo.Commit();
        }


        public JobBooking GetJobBookingById(long id)
        {
            return jobBookingRepo.List().Where(x => x.IsDeleted == false).ToList().Where(x => x.ID == id).First();

        }

        public void DeleteJobBooking(JobBooking jobBooking)
        {
            jobBookingRepo.Delete(jobBooking);
            jobBookingRepo.Commit();
        }

        public void UpdateJobBooking(JobBooking jobBooking)
        {
            jobBookingRepo.Update(jobBooking);
            jobBookingRepo.Commit();
        }

        public virtual IList<JobBooking> GetAllJobBooking(JobBooking jobBooking, long customerId, long staffId, DateTime? from, DateTime? to)
        {
            return jobBookingRepo.GetAllJobBooking(jobBooking, customerId, staffId, from, to);
        }

        public IList<JobBooking> GetJobBookingByInvoiceId(long invoiceId)
        {
            return jobBookingRepo.GetJobBookingByInvoiceId(invoiceId); ;
        }
    }
}
